#define _CRT_SECURE_NO_WARNINGS 1
#include "CycleQueue.h"
MyCircularQueue::MyCircularQueue(int k)
{
	_a = (int*)malloc(sizeof(int) * k + 1);
	_front = _rear = 0;
	_k = k;
}
bool MyCircularQueue::isEmpty()
{
	return _front == _rear;
}
bool MyCircularQueue::isFull()
{
	return (_rear + 1) % (_k + 1) == _front;
}
bool MyCircularQueue::enQueue(int value)
{
	if (isFull())
	{
		return false;
	}
	_a[_rear] = value;
	_rear++;
	_rear %= _k + 1;
	return true;
}
bool MyCircularQueue::deQueue()
{
	if(isEmpty())
	{
		return false;
	}
	++_front;
	_front %= _k + 1;
	return true;
}
int MyCircularQueue::Front()
{
	if (isEmpty())
	{
		return -1;
	}
	return _a[_front];
}
int MyCircularQueue::Rear()
{
	if (isEmpty())
	{
		return -1;
	}
	return _a[(_rear - 1 + _k - 1) % (_k + 1)];
}
